#pragma once

#include <ctime>

#include <string>
#include <map>
#include <memory>

#include "util/fs.h"

#include "template.h"

namespace html::tmplt
{

class Factory
{
private:

    class TemplateCache
    {
    public:
        TemplateCache(const fs::path &path, fs::file_time_type timestamp)
            : template_(path), timestamp_(timestamp) {
        }

        const Template &get() const {
            return template_;
        }

        fs::file_time_type timestamp() const {
            return timestamp_;
        }

    private:
        const Template template_;
        const fs::file_time_type timestamp_;
    };

public:
    explicit Factory(const std::string &rootDir);

    ~Factory();

    const Template *byPath(const std::string &relative);

    const std::string &title() const {
        return title_;
    }

private:

private:
    const std::string title_;
    const fs::path rootDir_;
    std::map<std::string, std::shared_ptr<TemplateCache>> map_;
};

} // namespace html::tmplt
